package cn.yj.message;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 永健
 * @since 2022-02-09 09:36
 */
@Component
public class OrderQueueListener {

    @RabbitListener(queues = "ORDER_QUEUE")
    public void process(Message message, Channel channel) throws IOException {

        Object o = message.getMessageProperties().getHeaders().get("cn.yj");
        if (o == null || !o.toString().equals("781267910")) {
            // 消费成功，删除队列里的消息
            // channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
            System.out.println("接收到不符合规范的消息，不进行消费:" + message);
            return;
        }
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        System.out.println("接收到消息：" + new String(message.getBody(), "UTF-8"));
    }
}
